package com.raccoonagents.tools.cascet2d.model.components;

import org.lwjgl.opengl.GL11;

import com.raccoonagents.tools.cascet2d.interfaces.rendering.IMaskedTexturedRenderable;
import com.raccoonagents.tools.cascet2d.model.Text;
import com.raccoonagents.tools.cascet2d.model.Vector2f;
import com.raccoonagents.tools.cascet2d.util.CalculationUtils;
import com.raccoonagents.tools.cascet2d.util.FontUtils;
import com.raccoonagents.tools.cascet2d.util.GraphicUtil;

public class LabeledTexturedButton extends AbstractButton implements IMaskedTexturedRenderable{
	protected int texture = -1;
	protected int mask = -1;
	protected Text text;
	
	public LabeledTexturedButton(final String text,final Vector2f size, final int texture, final int mask) {
		super(size);
		this.texture = texture;
		this.mask = mask;
		this.text = new Text(text);
		this.text.setLocation(CalculationUtils.getCenteredPosition(this.size,this.text.getSize()));
		
	}
	
	@Override
	public void onClick() {
		text.setColor(new float []{1.0f,1.0f,1.0f});		
	}

	@Override
	public void onMouseOut() {
		text.setColor(new float []{1.0f,1.0f,1.0f});		
	}

	@Override
	public void onMouseOver() {
		text.setColor(new float []{1.0f,1.0f,0.0f});
	}
	
	@Override
	public void onPress() {
		text.setColor(new float []{1.0f,1.0f,1.0f});		
	}

	@Override
	public float [] getColor() {
		return new float []{1.0f,1.0f,1.0f};
	}

	@Override
	public float getOpacity() {
		return 1.0f;
	}


	@Override
	public float getRotation() {
		return 0;
	}

	@Override
	public void render() {
		if(!visible){
			return;
		}
		
		if(mask != -1){
			GraphicUtil.renderMaskedImage(this);			
		}else{
			GraphicUtil.renderImage(this);						
		}
		
		GL11.glPushMatrix();
		GL11.glTranslatef(this.localLocation.x, this.localLocation.y, 0);
		FontUtils.renderText(text);
		GL11.glPopMatrix();
	}

	@Override
	public int getTexture() {
		return texture;
	}

	@Override
	public int getMaskImage() {
		return mask;
	}

}
